package com.lange.autocode.customDict;

import cn.net.autocode.core.bean.ResultT;
import cn.net.autocode.core.utils.TreeUtils;
import cn.net.autocode.dbManager.Dao;
import cn.net.autocode.platform.customDict.CustomDict;
import cn.net.autocode.platform.customDict.CustomDictAnnotation;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;

@Component
@CustomDictAnnotation("organ")
public class SysOrganTree implements CustomDict {

    private final Dao dao;

    public SysOrganTree(Dao dao) {
        this.dao = dao;
    }

    @Override
    public ResultT query(JSONObject param) {
        JSONArray array = dao.queryJSONArray("select code value,label,id,parent_id from sys_organ order by sort_no");
        JSONArray treeArray = TreeUtils.commonTree(array);
        return ResultT.success(treeArray);
    }
}
